﻿
#region License, Terms and Conditions
//
// ProjectService.cs
//
// Authors: Kori Francis <twitter.com/djbyter>
// Copyright (C) 2012 Kori Francis. All rights reserved.
// 
// THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW:
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#endregion

namespace BugHerder.Core
{
    #region Imports
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    #endregion

    /// <summary>
    /// TODO
    /// </summary>
    public class ProjectService : BugHerdApiBase
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="username">The API username to use when accessing the API</param>
        /// <param name="password">The API password to use when accessing the API</param>
        public ProjectService(string username, string password)
            : base(username, password)
        { }

        /// <summary>
        /// Get a list of all active and inactive projects you are a member of.
        /// </summary>
        /// <returns>The list of projects</returns>
        public IEnumerable<Project> All()
        {
            return GetRequest<List<Project>>("/projects");
        }

        /// <summary>
        /// Show details for a specific project. 
        /// </summary>
        /// <remarks>Note: if you'd like to see the tasks in the project, refer to section 'List tasks'.</remarks>
        /// <param name="projectId">The id of the project to retreive</param>
        /// <returns>The retrieved project</returns>
        public Project Single(int projectId)
        {
            return GetRequest<Project>("/projects/{0}", projectId);
        }

        /// <summary>
        /// Create a new project. Note: this is subject to plan limits.
        /// </summary>
        /// <param name="project">The project to create</param>
        /// <returns>The created project</returns>
        public Project Create(Project project)
        {
            return PostRequest<Project, Project>(project, "/projects");
        }

        /// <summary>
        /// Update settings for an existing project under your control (ie: only the ones you own).
        /// </summary>
        /// <param name="project">The project to update</param>
        public void Update(Project project)
        {
            PutRequest<Project, Project>(project, "/projects/{0}", project.Id);
        }

        /// <summary>
        /// Delete method for projects
        /// </summary>
        /// <param name="projectId">The projectId to delete</param>
        public void Delete(int projectId)
        {
            DeleteRequest("/projects/{0}", projectId);
        }
    }
}

